/**
 * 
 */
package com.zcy.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zcy.dao.UserDao;
import com.zcy.model.User;
import com.zcy.pageModel.Puser;
import com.zcy.service.UserService;

/**
 * @author 周成瑜
 *
 */
@Service("userService")
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;
	
	@Override
	public void save(Puser puser) {
		User u=new User();
		BeanUtils.copyProperties(puser, u);//使用spring的工具类来讲页面属性赋值到hibernate的属性
		u.setCreattime(new Date());
		userDao.save(u);
	}

	
	@Override
	public Puser login(Puser puser) {
		Map<String, Object> params = new HashMap<String, Object>();
		String hql="from User u where u.username=:username and u.password=:password";
		//尽量使用该方法，防止sql注入
		params.put("username", puser.getUsername());
		params.put("password", puser.getPassword());
		User u=userDao.get(hql,params);
		if(u!=null){
			return puser;
		}else {
			return null;
		}
	}
	

}
